package com.chixing.controller;

import com.chixing.commons.Result;
import com.chixing.pojo.CompanyManage;
import com.chixing.service.ICompanyManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 高管信息表 前端控制器
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@Controller
public class CompanyManageController {
    @Autowired
    private ICompanyManageService companyManageService;


    //后台
    @RequestMapping("backStageCompanyManage/save")
    @ResponseBody
    public Result saveManage(CompanyManage companyManage){
        boolean b = companyManageService.insertManage(companyManage);
        if (b) {
            return new Result(20000,"添加成功");
        }
        return new Result(20001,"添加失败");
    }

    @RequestMapping("backStageCompanyManage/update")
    @ResponseBody
    public Result updateManage(CompanyManage companyManage, HttpSession session){
        boolean b = companyManageService.updateManage(companyManage);
        if (b) {
            session.setAttribute("loginuser", companyManage);
            return new Result(20000,"高管信息修改成功",companyManage);
        }
        return new Result(20001,"高管信息修改失败");
    }

    @RequestMapping("backStageCompanyManage/orderPass")
    @ResponseBody
    public Result selectOrderManagePass(@RequestParam("orderPassword") String orderPassword, HttpSession session){
        CompanyManage companyManage = companyManageService.selectOrderManagePass(orderPassword,session);
        if (companyManage!=null) {
            return new Result(20000,"旧密码没啥问题");
        }
        return new Result(20001,"旧密码没查到");
    }

    @RequestMapping("backStageCompanyManage/updatePass")
    @ResponseBody
    public Result updatePass(String newPassword, HttpSession session){
        boolean b = companyManageService.updatePass(newPassword, session);
        if (b) {
            return new Result(20000,"修改密码成功");
        }
        return new Result(20001,"修改密码失败");
    }

}
